# from typing import Any
# from config import Settings
# from fastapi import FastAPI, Depends
# import uvicorn
# from pydantic import BaseModel
# from functools import lru_cache
# from sql_app.dependencies import get_query_token, get_token_header
# from sql_app.router import items, user
#
#
# '''
#     多文件场景
# '''
#
# app = FastAPI(dependencies=[Depends(get_query_token)])
# app.include_router(user.router)
# app.include_router(items.router)
#
#
# @lru_cache
# def get_settings():
#     return Settings()
#
#
# @app.get("/")
# async def index():
#     return {"message": "Hello World"}
#
#
# @app.get("/getConfig")
# async def getConfig():
#     return {
#         "app_name": Settings().app_name,
#         "admin_email": Settings().admin_email,
#         "items_per_user": Settings().items_per_user,
#     }
#
#
# class Item(BaseModel):
#     name: str
#     description: str or None = None
#     price: float
#     tax: float or None = None
#     tags: list[str] = []
#
#
# @app.get("/getItem", response_model=list[Item])
# async def index() -> Any:
#     return [
#         {"name": "Portal Gun", "price": 42.0},
#         {"name": "Plumbus", "price": 32.0},
#     ]
#
#
# if __name__ == '__main__':
#     uvicorn.run(app='main:app', host="127.0.0.1", port=get_settings().port, reload=True)

import uvicorn
from fastapi import FastAPI
from sql_app.models import models
from sql_app.database import SessionLocal, engine
from sql_app.router import user
from config.config import config


models.Base.metadata.create_all(bind=engine)

app = FastAPI()

app.include_router(user.router)


# Dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()


if __name__ == '__main__':
    print(config.port, config.app_name, config.app_version)
    uvicorn.run(app='main:app', host="127.0.0.1", port=8081, reload=True)
